
function YKG(){}

var ykg = new YKG();

/**
 *静态方法
 *@use 静态实例化各个模块
 *@example YKG.app('form').alert("KK");
 *这样就可以调form模块下的alert()的函数组件
 */
YKG.app = function(name){
    var model = 'new ykg.' + name +'()';    
    eval('app ='+model);    
    return app;
}


//显示/隐藏文本内容
YKG.prototype.showNext = function(object) {
	
	if(object.attr("alt") != '隐藏') {
		object.attr("alt", "隐藏");
		object.attr("title", object.text());
		object.text(object.attr("alt"));
	}else{
		object.text(object.attr("title"));	
		object.attr("title",object.attr("alt"));
		object.attr("alt", object.text());
			
	}	
	console.log(object.text());
	object.next().slideToggle("slow");
	
	return false;
	
}

YKG.prototype.widget = function(){
    
    this.float = function(sidebar){
        
        var html = $('<ul></ul>').css({
            
            'id':'float-nav',
            'border':'1px solid gray',
            'position':'fixed',
            'top':$(window).height()/2,
            'right':10,
            'text-align':'right',
            'padding':5
            
            
        });
        
        var items = new Array();
        
        sidebar.find('.widget').hide().find('h5').each(function(){
            items.push($(this).text());
            
            $('<li>' + $(this).text() + '</li>').appendTo(html);
            
        });
        
        console.log(html);
        
        html.appendTo($("body"));
        
        
        
        html.children().toggle(function(){
            $(this).css({'border-bottom':'2px dashed gray','padding':5});
            sidebar.find('.widget:eq('+$(this).index()+')').fadeIn();
        },function(){
            $(this).css({'border-bottom':'1px dashed gray','padding':5});
            sidebar.find('.widget:eq('+$(this).index()+')').fadeOut();
        });
        
        
        
        
        
        console.log(items);
        
        
    }
    
}

$(function(){
   //YKG.app('widget').float($("#sidebar")); 
});

YKG.prototype.form = function(){
    
    /**
     *根据文本框的Title自动提示文本框标题
     */
    this.autoTips = function(){
      	$(":input").val(function(){
      	 
            //如果文本框有默认的内容，则显示默认内容，不然就显示title内容         
      	     if($(this).val() != '' && $(this).val() != $(this).attr("title")){
      	        return $(this).val();
      	     }else{
      	         return $(this).attr("title"); 
      	     }
      		
      	}).focus(function(){
      		if($(this).val() == $(this).attr("title")){
      			$(this).val('');
      		}
      	}).blur(function(){
      		if($(this).val() == ''){
      			$(this).val($(this).attr("title"));
      		}
      	});        
    } 

    
}



